package cn.tedu.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class SaveSessionServlet
 */
public class SaveSessionServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//getSession()方法会自动管理Session对象
		//如果没有Session对象就会自动创建Session对象
		//并且从response下发SessionID  Cookie到浏览器
		//如果浏览器请求中的SessionID对应的服务端
		//有对应的Session对象,则返回已经存在的Session对象
		HttpSession session=request.getSession();
		session.setAttribute("msg", "hello!");
		System.out.println(session.getId());
		response.setContentType("text/html;charset=utf-8");
		response.getWriter().println("save ok");
	}

}
